package cn.com.css.taxInspection.statistics.service.impl;

import cn.com.css.taxInspection.attention.entity.AjcxRecord;
import cn.com.css.taxInspection.attention.service.AjcxRecordService;
import cn.com.css.taxInspection.statistics.entity.*;
import cn.com.css.taxInspection.statistics.mapper.StatisticsMapper;
import cn.com.css.taxInspection.statistics.service.JcxlgjczrkqkService;
import cn.com.css.taxInspection.statistics.service.StatisticsService;
import cn.com.css.taxInspection.statistics.vo.AjxzReq;
import cn.com.css.taxInspection.statistics.vo.JcjfReq;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.DateUtils;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workquality.vo.req.SelectchiefReqVo;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.*;


@Slf4j
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Resource
    private HttpSessionService httpSessionService;
    @Resource
    private StatisticsMapper statisticsMapper;
    @Resource
    private JcxlgjczrkqkService jcxlgjczrkqkService;
    @Resource
    private AjcxRecordService ajcxRecordService;

    //查询积案进展-临时写法
    @Override
    @DS("oracle")
    public List<Map<String, String>> queryJajz(String ssdw) {
        return statisticsMapper.queryJajz(ssdw);
    }

    //查询工作质效-临时写法
    @Override
    @DS("oracle")
    public Page<Jcxlgjczrkqk> queryJcxlgjczrkqk(Jcxlgjczrkqk jcxlgjczrkqk) {
        Page<Jcxlgjczrkqk> page = new Page<>(jcxlgjczrkqk.getPage(), jcxlgjczrkqk.getLimit());
        LambdaQueryWrapper<Jcxlgjczrkqk> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.orderByAsc(Jcxlgjczrkqk::getId);
        return jcxlgjczrkqkService.page(page, queryWrapper);
    }

    @Override
    @DS("oracle")
    public List<Jcjf> jcjfStatistics(JcjfReq req) {
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String swjgDmTmp = currentSwjgDm.substring(0, 9);
        String excludeSwjgDm = swjgDmTmp + "49";
        String swjgDm = swjgDmTmp + "00";
        List<Jcjf> jcjfs = null;

        if (req.getStatisticsMonth().equals("0")) {
            jcjfs = statisticsMapper.jcjfStatisticsByFullYear(req.getStatisticsYear(), req.getStatisticsMonth()
                    , excludeSwjgDm, swjgDm);
        } else {
            jcjfs = statisticsMapper.jcjfStatistics(req.getStatisticsYear(), req.getStatisticsMonth(), excludeSwjgDm, swjgDm);
        }
        //计算科室积分
        double jconek = 0;
        double jctwok = 0;
        double jcthreek = 0;
        double jcfourk = 0;
        double jcfivek = 0;
        for (Jcjf jcjf : jcjfs) {
            String swjgdm = jcjf.getSwjgDm();
            String cbjf = jcjf.getCbdf();
            String rkjf = jcjf.getRkdf();
            String sxjf = jcjf.getZxdf();
            jcjf.setCbdf(String.format("%.2f", Double.valueOf(cbjf)));
            jcjf.setRkdf(String.format("%.2f", Double.valueOf(rkjf)));
            jcjf.setZxdf(String.format("%.2f", Double.valueOf(sxjf)));
            double totaljf = Double.valueOf(cbjf) + Double.valueOf(rkjf) + Double.valueOf(sxjf);
            if (swjgdm.equals(swjgDmTmp + "41")) {
                jconek += totaljf;
            }
            if (swjgdm.equals(swjgDmTmp + "42")) {
                jctwok += totaljf;
            }
            if (swjgdm.equals(swjgDmTmp + "43")) {
                jcthreek += totaljf;
            }
            if (swjgdm.equals(swjgDmTmp + "44")) {
                jcfourk += totaljf;
            }
            if (swjgdm.equals(swjgDmTmp + "45")) {
                jcfivek += totaljf;
            }
        }

        for (Jcjf jcjf : jcjfs) {
            jcjf.setSwjgjc(jcjf.getSwjgjc().replace("沈阳市税务局", ""));
            //计算个人积分
            String cbjf = jcjf.getCbdf();
            String rkjf = jcjf.getRkdf();
            String sxjf = jcjf.getZxdf();
            Double grhj = Double.valueOf(cbjf) + Double.valueOf(rkjf) + Double.valueOf(sxjf);
            jcjf.setGrhj(String.format("%.2f", grhj));
            String swjgdm = jcjf.getSwjgDm();
            if (swjgdm.equals(swjgDmTmp + "41")) {
                jcjf.setKsjf(String.format("%.2f", jconek));
            }
            if (swjgdm.equals(swjgDmTmp + "42")) {
                jcjf.setKsjf(String.format("%.2f", jctwok));
            }
            if (swjgdm.equals(swjgDmTmp + "43")) {
                jcjf.setKsjf(String.format("%.2f", jcthreek));
            }
            if (swjgdm.equals(swjgDmTmp + "44")) {
                jcjf.setKsjf(String.format("%.2f", jcfourk));
            }
            if (swjgdm.equals(swjgDmTmp + "45")) {
                jcjf.setKsjf(String.format("%.2f", jcfivek));
            }
            jcjf.setOtherJf("0");
        }
        return jcjfs;
    }

    @Override
    @DS("oracle")
    public List<Jcjf> jcjfStatisticsXz(JcjfReq req) {
        List<Jcjf> jcjfs = statisticsMapper.jcjfStatisticsXz(req.getStatisticsYear(), req.getStatisticsMonth(), req.getSwryDm());
        return jcjfs;
    }

    @Override
    @DS("oracle")
    public List<Sljf> sljfStatistics(JcjfReq req) {
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String swjgDmTmp = currentSwjgDm.substring(0, 9);
        String excludeSwjgDm = swjgDmTmp + "50";
        String swjgDm = swjgDmTmp + "00";
        List<Sljf> sljfs = null;

        if (req.getStatisticsMonth().equals("0")) {
            sljfs = statisticsMapper.sljfStatisticsByFullYear(req.getStatisticsYear(), req.getStatisticsMonth(), excludeSwjgDm, swjgDm);
        } else {
            sljfs = statisticsMapper.sljfStatistics(req.getStatisticsYear(), req.getStatisticsMonth(), excludeSwjgDm, swjgDm);
        }
        //计算科室积分
        double ksjftotal = 0;
        for (Sljf sljf : sljfs) {
            String cbjf = sljf.getCbdf();
            String rkjf = sljf.getRkdf();
            String sxjf = sljf.getZxdf();
            sljf.setCbdf(String.format("%.2f", Double.valueOf(cbjf)));
            sljf.setRkdf(String.format("%.2f", Double.valueOf(rkjf)));
            sljf.setZxdf(String.format("%.2f", Double.valueOf(sxjf)));
            Double grhj = Double.valueOf(cbjf) + Double.valueOf(rkjf) + Double.valueOf(sxjf);
            ksjftotal += grhj;
        }


        for (Sljf sljf : sljfs) {
            sljf.setSwjgjc(sljf.getSwjgjc().replace("沈阳市税务局", ""));
            //计算个人合计
            String cbjf = sljf.getCbdf();
            String rkjf = sljf.getRkdf();
            String sxjf = sljf.getZxdf();
            Double grhj = Double.valueOf(cbjf) + Double.valueOf(rkjf) + Double.valueOf(sxjf);
            sljf.setGrhj(String.format("%.2f", grhj));
            sljf.setKsjf(String.format("%.2f", ksjftotal));
            sljf.setOtherJf("0");
        }
        return sljfs;
    }

    @Override
    @DS("oracle")
    public List<Sljf> sljfStatisticsXz(JcjfReq req) {
        List<Sljf> sljfs = statisticsMapper.sljfStatisticsXz(req.getStatisticsYear(), req.getStatisticsMonth(), req.getSwryDm());
        return sljfs;
    }

    @Override
    @DS("oracle")
    public List<Zxjf> zxjfStatistics(JcjfReq req) {
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String swjgDmTmp = currentSwjgDm.substring(0, 9);
        String excludeSwjgDm = swjgDmTmp + "60";
        String swjgDm = swjgDmTmp + "00";
        List<Zxjf> zxjfs = null;

        if (req.getStatisticsMonth().equals("0")) {
            zxjfs = statisticsMapper.zxjfStatisticsByFullYear(req.getStatisticsYear(), req.getStatisticsMonth()
                    , excludeSwjgDm, swjgDm);
        } else {
            zxjfs = statisticsMapper.zxjfStatistics(req.getStatisticsYear(), req.getStatisticsMonth(), excludeSwjgDm, swjgDm);
        }

        //计算科室积分
        double ksjftotal = 0;
        for (Zxjf zxjf : zxjfs) {
            String rkjf = zxjf.getRkdf();
            //String cbjf = zxjf.getCbdf();
            zxjf.setRkdf(String.format("%.2f", Double.valueOf(rkjf)));
            //zxjf.setCbdf(String.format("%.2f",Double.valueOf(cbjf)));
            Double grhj = Double.valueOf(rkjf);
            ksjftotal += grhj;
        }

        for (Zxjf zxjf : zxjfs) {
            zxjf.setSwjgjc(zxjf.getSwjgjc().replace("沈阳市税务局", ""));
            //计算个人合计
            String rkjf = zxjf.getRkdf();
            //String cbjf = zxjf.getCbdf();
            Double grhj = Double.valueOf(rkjf);
            zxjf.setGrhj(String.format("%.2f", grhj));
            zxjf.setKsjf(String.format("%.2f", ksjftotal));
            zxjf.setOtherJf("0");
        }
        return zxjfs;
    }

    @Override
    @DS("oracle")
    public List<Zxjf> zxjfStatisticsXz(JcjfReq req) {
        List<Zxjf> zxjfs = statisticsMapper.zxjfStatisticsXz(req.getStatisticsYear(), req.getStatisticsMonth(), req.getSwryDm());
        return zxjfs;
    }

    @Override
    @DS("oracle")
    public List<IncomeCheckSupplement> rukuStatistics(JcjfReq req) {
        paramHandler(req);
        return statisticsMapper.rukuStatistics(req);
    }

    @Override
    @DS("oracle")
    public List<IncomeCheckSupplement> chabuStatistics(JcjfReq req) {
        paramHandler(req);
        return statisticsMapper.chabuStatistics(req);
    }

    @Override
    @DS("oracle")
    public Map<String, List> indexQsjcsr(String dataScope) {
        Map<String, List> resMap = new HashMap<>();
        List<String> categoryData = new ArrayList<>();
        List<Double> seriesData = new ArrayList<>();
        List<Map<String, Object>> qsjcsrMapData = null;
        if ("jcyj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            qsjcsrMapData = statisticsMapper.indexQsjcsr();
        } else if ("sysj".equals(dataScope)) {
            qsjcsrMapData = statisticsMapper.indexQsjcsrSysj();
        }
        double total = 0.00;
        for (Map objMap : qsjcsrMapData) {
            categoryData.add(String.valueOf(objMap.get("SWJGMC")));
            seriesData.add(Double.valueOf(String.valueOf(objMap.get("JE"))));
            total += Double.valueOf(String.valueOf(objMap.get("JE")));
        }
        categoryData.add("全市");
        String formatTotal = String.format("%.2f", total);
        seriesData.add(Double.valueOf(formatTotal));
//        seriesData.add(total);
        resMap.put("categoryData", categoryData);
        resMap.put("seriesData", seriesData);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, List> indexCbAndRk(String dataScope) {
        Map<String, List> resMap = new HashMap<>();
        List<Double> cbData = new ArrayList<>();
        List<Double> rkData = new ArrayList<>();
        List<Map<String, Object>> cbMapData = null;
        List<Map<String, Object>> rkMapData = null;
        if ("jcyj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            cbMapData = statisticsMapper.indexCb();
            rkMapData = statisticsMapper.indexRk();
        } else if ("sysj".equals(dataScope)) {
            cbMapData = statisticsMapper.indexCbSysj();
            rkMapData = statisticsMapper.indexRkSysj();
        }
        for (Map objMap : cbMapData) {
            cbData.add(Double.valueOf(String.valueOf(objMap.get("CB"))));
        }
        for (Map objMap : rkMapData) {
            rkData.add(Double.valueOf(String.valueOf(objMap.get("RK"))));
        }
        resMap.put("cbData", cbData);
        resMap.put("rkData", rkData);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> indexCbAndRkNew() {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        Map<String, Object> resMap = new HashMap<>();
        //按月
        List<Double> cbDataByMonth = new ArrayList<>();
        List<Double> rkDataByMonth = new ArrayList<>();
        List<Map<String, Object>> cbMapData = null;
        List<Map<String, Object>> rkMapData = null;
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            cbMapData = statisticsMapper.indexCbByMonth(currentSwjgDm.substring(0, 9));
            rkMapData = statisticsMapper.indexRkByMonth(currentSwjgDm.substring(0, 9));
        } else if ("all".equals(dataScope)) {
            cbMapData = statisticsMapper.indexCbSysjByMonth();
            rkMapData = statisticsMapper.indexRkSysjByMonth();
        }
        for (Map objMap : cbMapData) {
            cbDataByMonth.add(Double.valueOf(String.valueOf(objMap.get("cb"))));
        }
        for (Map objMap : rkMapData) {
            rkDataByMonth.add(Double.valueOf(String.valueOf(objMap.get("rk"))));
        }

        resMap.put("cbDataByMonth", cbDataByMonth);
        resMap.put("rkDataByMonth", rkDataByMonth);
        //按机关
        List<Double> cbDataBySwjg = new ArrayList<>();
        List<Double> rkDataBySwjg = new ArrayList<>();
        List<String> cbrkbyswjg_xAxis_data = new ArrayList<>();

        List<Map<String, Object>> cbBySwjgMapData = null;
        List<Map<String, Object>> rkBySwjgMapData = null;
        dataScope = "jcj";
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            cbBySwjgMapData = statisticsMapper.indexCbBySwjg(currentSwjgDm.substring(0, 9));
            rkBySwjgMapData = statisticsMapper.indexRkBySwjg(currentSwjgDm.substring(0, 9));
        } else if ("all".equals(dataScope)) {
            cbBySwjgMapData = statisticsMapper.indexCbSysjBySwjg();
            rkBySwjgMapData = statisticsMapper.indexRkSysjBySwjg();
        }
        for (Map objMap : cbBySwjgMapData) {
            cbDataBySwjg.add(Double.valueOf(String.valueOf(objMap.get("cb"))));
        }
        for (Map objMap : rkBySwjgMapData) {
            rkDataBySwjg.add(Double.valueOf(String.valueOf(objMap.get("rk"))));
            cbrkbyswjg_xAxis_data.add(String.valueOf(objMap.get("swjgmc")));
        }
        resMap.put("cbDataBySwjg", cbDataBySwjg);
        resMap.put("rkDataBySwjg", rkDataBySwjg);
        resMap.put("cbrkbyswjg_xAxis_data", cbrkbyswjg_xAxis_data);
        //稽查收入
        List<String> categoryData = new ArrayList<>();
        List<Double> seriesData = new ArrayList<>();
        List<Map<String, Object>> qsjcsrMapData = null;
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            qsjcsrMapData = statisticsMapper.indexQsjcsrNew(currentSwjgDm.substring(0, 9));
        } else if ("all".equals(dataScope)) {
            qsjcsrMapData = statisticsMapper.indexQsjcsrSysjNew();
        }
        double total = 0.00;
        for (Map objMap : qsjcsrMapData) {
            categoryData.add(String.valueOf(objMap.get("swjgmc")));
            seriesData.add(Double.valueOf(String.valueOf(objMap.get("je"))));
            total += Double.valueOf(String.valueOf(objMap.get("je")));
        }
        categoryData.add("全市");
        String formatTotal = String.format("%.2f", total);
        seriesData.add(Double.valueOf(formatTotal));

        resMap.put("jcrktj_categoryData", categoryData);
        resMap.put("jcrktj_seriesData", seriesData);
        resMap.put("dataScope", dataScope);
        return resMap;
    }

    @Override
    public Map<String, Object> jianjinzhan(String swjgDm) {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        List<Map<String, Object>> resDatas = new ArrayList<>();
        List<Map<String, Object>> tableHjDatas = new ArrayList<>();
        Map<String, Object> hjMap = new HashMap<>();
        if (!TsBqUtils.isNull(swjgDm)) {
            tableDatas = statisticsMapper.jianjinzhan(swjgDm.substring(0, 9));
        } else {
            if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
                tableDatas = statisticsMapper.jianjinzhan(currentSwjgDm.substring(0, 9));
            } else if ("all".equals(dataScope)) {
                tableDatas = statisticsMapper.jianjinzhanSysj();
            }
        }
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        int yljctotal = 0;
        int ylsltotal = 0;
        int ylzxtotal = 0;
        int ylbjtotal = 0;
        int yljatotal = 0;
        int ylothertotal = 0;
        int ylhjtotal = 0;
        int eljctotal = 0;
        int elsltotal = 0;
        int elzxtotal = 0;
        int elbjtotal = 0;
        int eljatotal = 0;
        int elothertotal = 0;
        int elhjtotal = 0;
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            int jc = Integer.valueOf(String.valueOf(currentMap.get("JCSL")));
            int sl = Integer.valueOf(String.valueOf(currentMap.get("SLSL")));
            int zx = Integer.valueOf(String.valueOf(currentMap.get("ZXSL")));
            int bj = Integer.valueOf(String.valueOf(currentMap.get("BJSL")));
            int ja = Integer.valueOf(String.valueOf(currentMap.get("JASL")));
            int eljc = Integer.valueOf(String.valueOf(currentMap.get("ELJCSL")));
            int elsl = Integer.valueOf(String.valueOf(currentMap.get("ELSLSL")));
            int elzx = Integer.valueOf(String.valueOf(currentMap.get("ELZXSL")));
            int elbj = Integer.valueOf(String.valueOf(currentMap.get("ELBJSL")));
            int elja = Integer.valueOf(String.valueOf(currentMap.get("ELJASL")));
            int ylother = 0;
            int elother = 0;
            int yltotal = jc + sl + zx + bj + ja;
            int eltotal = eljc + elsl + elzx + elbj + elja;
            currentMap.put("ylother", 0);
            currentMap.put("elother", 0);
            currentMap.put("yltotal", yltotal);
            currentMap.put("eltotal", eltotal);
            resDatas.add(currentMap);
            //增加合计行 2023-12-21 14:36:40
            yljctotal += jc;
            ylsltotal += sl;
            ylzxtotal += zx;
            ylbjtotal += bj;
            yljatotal += zx;
            ylothertotal += ylother;
            ylhjtotal += yltotal;
            eljctotal += eljc;
            elsltotal += elsl;
            elzxtotal += elzx;
            elbjtotal += elbj;
            eljatotal += elja;
            elothertotal += elother;
            elhjtotal += eltotal;
        }
        hjMap.put("yljctotal", yljctotal);
        hjMap.put("ylsltotal", ylsltotal);
        hjMap.put("ylzxtotal", ylzxtotal);
        hjMap.put("ylbjtotal", ylbjtotal);
        hjMap.put("yljatotal", yljatotal);
        hjMap.put("ylothertotal", ylothertotal);
        hjMap.put("ylhjtotal", ylhjtotal);
        hjMap.put("eljctotal", eljctotal);
        hjMap.put("elsltotal", elsltotal);
        hjMap.put("elzxtotal", elzxtotal);
        hjMap.put("elbjtotal", elbjtotal);
        hjMap.put("eljatotal", eljatotal);
        hjMap.put("elothertotal", elothertotal);
        hjMap.put("elhjtotal", elhjtotal);
        tableHjDatas.add(hjMap);
        resMap.put("tableHjDatas", tableHjDatas);
        resMap.put("tableDatas", resDatas);
        resMap.put("dataScope", dataScope);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> anyuanAndanjian(String swjgDm) {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        List<Map<String, Object>> resDatas = new ArrayList<>();
        List<Map<String, Object>> tableHjDatas = new ArrayList<>();
        Map<String, Object> hjMap = new HashMap<>();
        if (!TsBqUtils.isNull(swjgDm)) {
            tableDatas = statisticsMapper.anyuanAndanjian(swjgDm.substring(0, 9));
        } else {
            if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
                tableDatas = statisticsMapper.anyuanAndanjian(currentSwjgDm.substring(0, 9));
            } else if ("all".equals(dataScope)) {
                tableDatas = statisticsMapper.anyuanAndanjianSysj();
            }
        }
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        int snjctotal = 0;
        int bnxztotal = 0;
        int hjtotal = 0;
        int jctotal = 0;
        int sltotal = 0;
        int zxtotal = 0;
        int bjtotal = 0;
        int jatotal = 0;
        int ajzstotal = 0;
        int hstotal = 0;
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            int snjcsl = Integer.valueOf(String.valueOf(currentMap.get("snjcsl")));
            int bnxzsl = Integer.valueOf(String.valueOf(currentMap.get("bnxzsl")));
            int bnjcsl = Integer.valueOf(String.valueOf(currentMap.get("bnjcsl")));
            int bnslsl = Integer.valueOf(String.valueOf(currentMap.get("bnslsl")));
            int bnzxsl = Integer.valueOf(String.valueOf(currentMap.get("bnzxsl")));
            int bnbjsl = Integer.valueOf(String.valueOf(currentMap.get("bnbjsl")));
            int bnjasl = Integer.valueOf(String.valueOf(currentMap.get("bnjasl")));
            int nsrhssl = Integer.valueOf(String.valueOf(currentMap.get("nsrhssl")));
            int ayhj = snjcsl + bnxzsl;
            int ajzs = bnjcsl + bnslsl + bnzxsl + bnbjsl + bnjasl;
            currentMap.put("ayhj", ayhj);
            currentMap.put("ajzs", ajzs);
            resDatas.add(currentMap);
            //增加合计行 2023-12-21 14:36:40
            snjctotal += snjcsl;
            bnxztotal += bnxzsl;
            hjtotal += ayhj;
            jctotal += bnjcsl;
            sltotal += bnslsl;
            zxtotal += bnzxsl;
            bjtotal += bnbjsl;
            jatotal += bnjasl;
            ajzstotal += ajzs;
            hstotal += nsrhssl;
        }
        hjMap.put("snjctotal", snjctotal);
        hjMap.put("bnxztotal", bnxztotal);
        hjMap.put("hjtotal", hjtotal);
        hjMap.put("jctotal", jctotal);
        hjMap.put("sltotal", sltotal);
        hjMap.put("zxtotal", zxtotal);
        hjMap.put("bjtotal", bjtotal);
        hjMap.put("jatotal", jatotal);
        hjMap.put("ajzstotal", ajzstotal);
        hjMap.put("hstotal", hstotal);
        tableHjDatas.add(hjMap);
        resMap.put("tableHjDatas", tableHjDatas);
        resMap.put("tableDatas", resDatas);
        resMap.put("dataScope", dataScope);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> chabuandruku(String swjgDm) {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        List<Map<String, Object>> resDatas = new ArrayList<>();
        List<Map<String, Object>> tableHjDatas = new ArrayList<>();
        Map<String, Object> hjMap = new HashMap<>();
        if (!TsBqUtils.isNull(swjgDm)) {
            tableDatas = statisticsMapper.chabuandruku(swjgDm.substring(0, 9));
        } else {
            if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
                tableDatas = statisticsMapper.chabuandruku(currentSwjgDm.substring(0, 9));
            } else if ("all".equals(dataScope)) {
                tableDatas = statisticsMapper.chabuandrukuSysj();
            }
        }
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        Double cbskjetotal = 0.0;
        Double cbznjjetotal = 0.0;
        Double cbmswfsdjetotal = 0.0;
        Double cbfkjetotal = 0.0;
        Double cbzcjetotal = 0.0;
        Double rkskjetotal = 0.0;
        Double rkznjjetotal = 0.0;
        Double rkmswfsdjetotal = 0.0;
        Double rkfkjezstotal = 0.0;
        Double rkzcjetotal = 0.0;
        Double cbhjtotal = 0.0;
        Double rkhjtotal = 0.0;
        Double rkqzdfjtotal = 0.0;
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            Double cbskje = Double.valueOf(String.valueOf(currentMap.get("cbskje")));
            Double cbznjje = Double.valueOf(String.valueOf(currentMap.get("cbznjje")));
            Double cbmswfsdje = Double.valueOf(String.valueOf(currentMap.get("cbmswfsdje")));
            Double cbfkje = Double.valueOf(String.valueOf(currentMap.get("cbfkje")));
            Double cbzcje = Double.valueOf(String.valueOf(currentMap.get("cbzcje")));
            Double rkskje = Double.valueOf(String.valueOf(currentMap.get("rkskje")));
            Double rkznjje = Double.valueOf(String.valueOf(currentMap.get("rkznjje")));
            Double rkmswfsdje = Double.valueOf(String.valueOf(currentMap.get("rkmswfsdje")));
            Double rkfkje = Double.valueOf(String.valueOf(currentMap.get("rkfkje")));
            Double rkzcje = Double.valueOf(String.valueOf(currentMap.get("rkzcje")));
            Double rkzyjje = Double.valueOf(String.valueOf(currentMap.get("rkzyjje")));
            Double rkqzdfj = (rkskje + rkzcje) - rkzyjje;//入库-其中地方级=税款RKSKJE+RKZCJE自查-中央级RKZYJJE
            Double cbhj = cbskje + cbznjje + cbmswfsdje + cbfkje + cbzcje;
            Double rkhj = rkskje + rkznjje + rkmswfsdje + rkfkje + rkzcje;
            currentMap.put("cbskje", String.format("%.2f", cbskje));
            currentMap.put("cbznjje", String.format("%.2f", cbznjje));
            currentMap.put("cbmswfsdje", String.format("%.2f", cbmswfsdje));
            currentMap.put("cbfkje", String.format("%.2f", cbfkje));
            currentMap.put("cbzcje", String.format("%.2f", cbzcje));
            currentMap.put("rkskje", String.format("%.2f", rkskje));
            currentMap.put("rkznjje", String.format("%.2f", rkznjje));
            currentMap.put("rkmswfsdje", String.format("%.2f", rkmswfsdje));
            currentMap.put("rkfkje", String.format("%.2f", rkfkje));
            currentMap.put("rkzcje", String.format("%.2f", rkzcje));
            currentMap.put("cbhj", String.format("%.2f", cbhj));
            currentMap.put("rkhj", String.format("%.2f", rkhj));
            currentMap.put("rkqzdfj", String.format("%.2f", rkqzdfj));
            resDatas.add(currentMap);

            cbskjetotal += cbskje;
            cbznjjetotal += cbznjje;
            cbmswfsdjetotal += cbmswfsdje;
            cbfkjetotal += cbfkje;
            cbzcjetotal += cbzcje;
            rkskjetotal += rkskje;
            rkznjjetotal += rkznjje;
            rkmswfsdjetotal += rkmswfsdje;
            rkfkjezstotal += rkfkje;
            rkzcjetotal += rkzcje;
            cbhjtotal += cbhj;
            rkhjtotal += rkhj;
            rkqzdfjtotal += rkqzdfj;
        }
        hjMap.put("cbskjetotal", String.format("%.2f", Double.valueOf(cbskjetotal)));
        hjMap.put("cbznjjetotal", String.format("%.2f", Double.valueOf(cbznjjetotal)));
        hjMap.put("cbmswfsdjetotal", String.format("%.2f", Double.valueOf(cbmswfsdjetotal)));
        hjMap.put("cbfkjetotal", String.format("%.2f", Double.valueOf(cbfkjetotal)));
        hjMap.put("cbzcjetotal", String.format("%.2f", Double.valueOf(cbzcjetotal)));
        hjMap.put("cbhjtotal", String.format("%.2f", Double.valueOf(cbhjtotal)));
        hjMap.put("rkskjetotal", String.format("%.2f", Double.valueOf(rkskjetotal)));
        hjMap.put("rkznjjetotal", String.format("%.2f", Double.valueOf(rkznjjetotal)));
        hjMap.put("rkmswfsdjetotal", String.format("%.2f", Double.valueOf(rkmswfsdjetotal)));
        hjMap.put("rkfkjezstotal", String.format("%.2f", Double.valueOf(rkfkjezstotal)));
        hjMap.put("rkzcjetotal", String.format("%.2f", Double.valueOf(rkzcjetotal)));
        hjMap.put("rkhjtotal", String.format("%.2f", Double.valueOf(rkhjtotal)));
        hjMap.put("rkqzdfjtotal", String.format("%.2f", Double.valueOf(rkqzdfjtotal)));
        tableHjDatas.add(hjMap);
        resMap.put("tableHjDatas", tableHjDatas);
        resMap.put("tableDatas", resDatas);
        resMap.put("dataScope", dataScope);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> anyuanAndanjian_swry(String swjgDm) {
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        List<Map<String, Object>> resDatas = new ArrayList<>();
        List<Map<String, Object>> tableHjDatas = new ArrayList<>();
        Map<String, Object> hjMap = new HashMap<>();
        if (!TsBqUtils.isNull(swjgDm)) {
            tableDatas = statisticsMapper.anyuanAndanjian_swry(swjgDm);
        }
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        int jctotal = 0;
        int sltotal = 0;
        int zxtotal = 0;
        int bjtotal = 0;
        int jatotal = 0;
        int ajzstotal = 0;
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            int bnjcsl = Integer.valueOf(String.valueOf(currentMap.get("bnjcsl")));
            int bnslsl = Integer.valueOf(String.valueOf(currentMap.get("bnslsl")));
            int bnzxsl = Integer.valueOf(String.valueOf(currentMap.get("bnzxsl")));
            int bnbjsl = Integer.valueOf(String.valueOf(currentMap.get("bnbjsl")));
            int bnjasl = Integer.valueOf(String.valueOf(currentMap.get("bnjasl")));
            int ajzs = bnjcsl + bnslsl + bnzxsl + bnbjsl + bnjasl;
            currentMap.put("ajzs", ajzs);
            resDatas.add(currentMap);
            //增加合计行 2023-12-21 14:36:40
            jctotal += bnjcsl;
            sltotal += bnslsl;
            zxtotal += bnzxsl;
            bjtotal += bnbjsl;
            jatotal += bnjasl;
            ajzstotal += ajzs;
        }
        hjMap.put("jctotal", jctotal);
        hjMap.put("sltotal", sltotal);
        hjMap.put("zxtotal", zxtotal);
        hjMap.put("bjtotal", bjtotal);
        hjMap.put("jatotal", jatotal);
        hjMap.put("ajzstotal", ajzstotal);
        tableHjDatas.add(hjMap);
        resMap.put("tableHjDatas", tableHjDatas);
        resMap.put("tableDatas", resDatas);
        return resMap;
    }


    @Override
    public List<String> jianjinzhan_ddtxtgetlocalajbhs() {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        String currentFirstJiancaseId = TsBqUtils.getCaseIdBySwjgDmAndLevel(currentSwjgDm.substring(0, 9), "1");
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        List<String> resDatas = new ArrayList<>();
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            currentSwjgDm = currentSwjgDm.substring(0, 9);
        } else if ("all".equals(dataScope)) {
            currentSwjgDm = "0";
        }

        List<Map<String, Object>> ajbhsMap = statisticsMapper.jianjinzhan_ddtxtgetlocalajbhs(currentSwjgDm, currentFirstJiancaseId);
        Iterator<Map<String, Object>> iterator = ajbhsMap.iterator(); // 获取迭代器
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            resDatas.add(String.valueOf(currentMap.get("AJBH")));
        }
        return resDatas;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> jianjinzhan_ddtxtDatas(List<String> ajbhs) {
        Map<String, Object> resMap = new HashMap<>();
        List<String> yAxis_category_data = new ArrayList<>();
        List<String> series_jiancha_data = new ArrayList<>();
        List<String> series_shenli_data = new ArrayList<>();
        List<String> series_zhixing_data = new ArrayList<>();
        if (ajbhs.size() > 0) {
            List<Map<String, Object>> resDatas = statisticsMapper.jianjinzhan_ddtxtDatas(ajbhs);
            Iterator<Map<String, Object>> iterator = resDatas.iterator(); // 获取迭代器
            while (iterator.hasNext()) {
                Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
                String nsrmc = String.valueOf(currentMap.get("nsrmc"));
                String jcts = String.valueOf(currentMap.get("jcts"));
                String slts = String.valueOf(currentMap.get("slts"));
                String zxts = String.valueOf(currentMap.get("zxts"));
                yAxis_category_data.add(nsrmc);
                series_jiancha_data.add(jcts);
                series_shenli_data.add(slts);
                series_zhixing_data.add(zxts);
            }
        }
        resMap.put("yAxis_category_data", yAxis_category_data);
        resMap.put("series_jiancha_data", series_jiancha_data);
        resMap.put("series_shenli_data", series_shenli_data);
        resMap.put("series_zhixing_data", series_zhixing_data);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, List> indexAjxxZzt(String dataScope) {
        Map<String, List> resMap = new HashMap<>();
        List<Object> qj = new ArrayList<>();
        List<Object> k1 = new ArrayList<>();
        List<Object> k2 = new ArrayList<>();
        List<Object> k3 = new ArrayList<>();
        List<Object> k4 = new ArrayList<>();
        List<Object> k5 = new ArrayList<>();
        List<Map<String, Object>> ajxxZztMapData = null;
        if ("jcyj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            ajxxZztMapData = statisticsMapper.indexAjxxZzt();
        } else if ("sysj".equals(dataScope)) {
            ajxxZztMapData = statisticsMapper.indexAjxxZztSysj();
        }
        int lasTotal = 0;
        int zcsTotal = 0;
        int zssTotal = 0;
        int sjsTotal = 0;
        int jasTotal = 0;
        for (Map objMap : ajxxZztMapData) {
            String swjgmc = String.valueOf(objMap.get("SWJGDM"));
            Integer las = Integer.valueOf(String.valueOf(objMap.get("LAS")));
            Integer zcs = Integer.valueOf(String.valueOf(objMap.get("ZCS")));
            Integer zss = Integer.valueOf(String.valueOf(objMap.get("ZSS")));
            Integer sjs = Integer.valueOf(String.valueOf(objMap.get("SJS")));
            Integer jas = Integer.valueOf(String.valueOf(objMap.get("JAS")));
            lasTotal += las;
            zcsTotal += zcs;
            zssTotal += zss;
            sjsTotal += sjs;
            jasTotal += jas;
            switch (swjgmc) {
                case "12101009000":
                    k1.add("市稽查局");
                    k1.add(las);
                    k1.add(zcs);
                    k1.add(zss);
                    k1.add(sjs);
                    k1.add(jas);
                    break;
                case "12101009100":
                    k2.add("稽查一局");
                    k2.add(las);
                    k2.add(zcs);
                    k2.add(zss);
                    k2.add(sjs);
                    k2.add(jas);
                    break;
                case "12101009200":
                    k3.add("稽查二局");
                    k3.add(las);
                    k3.add(zcs);
                    k3.add(zss);
                    k3.add(sjs);
                    k3.add(jas);
                    break;
                case "12101009300":
                    k4.add("稽查三局");
                    k4.add(las);
                    k4.add(zcs);
                    k4.add(zss);
                    k4.add(sjs);
                    k4.add(jas);
                    break;
                case "12101009141":
                    k1.add("一科");
                    k1.add(las);
                    k1.add(zcs);
                    k1.add(zss);
                    k1.add(sjs);
                    k1.add(jas);
                    break;
                case "12101009142":
                    k2.add("二科");
                    k2.add(las);
                    k2.add(zcs);
                    k2.add(zss);
                    k2.add(sjs);
                    k2.add(jas);
                    break;
                case "12101009143":
                    k3.add("三科");
                    k3.add(las);
                    k3.add(zcs);
                    k3.add(zss);
                    k3.add(sjs);
                    k3.add(jas);
                    break;
                case "12101009144":
                    k4.add("四科");
                    k4.add(las);
                    k4.add(zcs);
                    k4.add(zss);
                    k4.add(sjs);
                    k4.add(jas);
                    break;
                case "12101009145":
                    k5.add("五科");
                    k5.add(las);
                    k5.add(zcs);
                    k5.add(zss);
                    k5.add(sjs);
                    k5.add(jas);
                    break;
            }
        }
        if ("jcyj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            qj.add("全局");
        } else if ("sysj".equals(dataScope)) {
            qj.add("全市");
        }
        qj.add(lasTotal);
        qj.add(zcsTotal);
        qj.add(zssTotal);
        qj.add(sjsTotal);
        qj.add(jasTotal);
        resMap.put("qj", qj);
        resMap.put("k1", k1);
        resMap.put("k2", k2);
        resMap.put("k3", k3);
        resMap.put("k4", k4);
        resMap.put("k5", k5);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> indexAjxxZztNew() {
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        Map<String, Object> resMap = new HashMap<>();
        List<Object> qj = new ArrayList<>();
        List<Object> k1 = new ArrayList<>();
        List<Object> k2 = new ArrayList<>();
        List<Object> k3 = new ArrayList<>();
        List<Object> k4 = new ArrayList<>();
        List<Object> k5 = new ArrayList<>();
        List<Object> kssj = new ArrayList<>();
        List<Map<String, Object>> ajxxZztMapData = null;
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcyj(稽查一局)、sysj(沈阳市局)
            ajxxZztMapData = statisticsMapper.indexAjxxZztNew(currentSwjgDm.substring(0, 9));
        } else if ("all".equals(dataScope)) {
            ajxxZztMapData = statisticsMapper.indexAjxxZztSysjNew();
        }

        int zcsTotal = 0;
        int zssTotal = 0;
        int zzxsTotal = 0;
        int zzjcsTotal = 0;
        int bjsTotal = 0;
        for (Map objMap : ajxxZztMapData) {
            String swjgDm = String.valueOf(objMap.get("swjgdm"));
            Integer zcs = Integer.valueOf(String.valueOf(objMap.get("zcs")));
            Integer zss = Integer.valueOf(String.valueOf(objMap.get("zss")));
            Integer zzxs = Integer.valueOf(String.valueOf(objMap.get("zzxs")));
            Integer zzjcs = Integer.valueOf(String.valueOf(objMap.get("zzjcs")));
            Integer bjs = Integer.valueOf(String.valueOf(objMap.get("bjs")));
            zcsTotal += zcs;
            zssTotal += zss;
            zzxsTotal += zzxs;
            zzjcsTotal += zzjcs;
            bjsTotal += bjs;
            switch (swjgDm) {
                case "12101009000":
                    k1.add("市稽查局");
                    k1.add(zcs);
                    k1.add(zss);
                    k1.add(zzxs);
                    k1.add(zzjcs);
                    k1.add(bjs);
                    break;
                case "12101009100":
                    k2.add("稽查一局");
                    k2.add(zcs);
                    k2.add(zss);
                    k2.add(zzxs);
                    k2.add(zzjcs);
                    k2.add(bjs);
                    break;
                case "12101009200":
                    k3.add("稽查二局");
                    k3.add(zcs);
                    k3.add(zss);
                    k3.add(zzxs);
                    k3.add(zzjcs);
                    k3.add(bjs);
                    break;
                case "12101009300":
                    k4.add("稽查三局");
                    k4.add(zcs);
                    k4.add(zss);
                    k4.add(zzxs);
                    k4.add(zzjcs);
                    k4.add(bjs);
                    break;
            }

            //处理各个稽查局的数据根据税务机关后两位来判断是几科
            switch (swjgDm.substring(9)) {
                case "41":
                    k1.add("一科");
                    k1.add(zcs);
                    k1.add(zss);
                    k1.add(zzxs);
                    k1.add(zzjcs);
                    k1.add(bjs);
                    break;
                case "42":
                    k2.add("二科");
                    k2.add(zcs);
                    k2.add(zss);
                    k2.add(zzxs);
                    k2.add(zzjcs);
                    k2.add(bjs);
                    break;
                case "43":
                    k3.add("三科");
                    k3.add(zcs);
                    k3.add(zss);
                    k3.add(zzxs);
                    k3.add(zzjcs);
                    k3.add(bjs);
                    break;
                case "44":
                    k4.add("四科");
                    k4.add(zcs);
                    k4.add(zss);
                    k4.add(zzxs);
                    k4.add(zzjcs);
                    k4.add(bjs);
                    break;
                case "45":
                    k5.add("五科");
                    k5.add(zcs);
                    k5.add(zss);
                    k5.add(zzxs);
                    k5.add(zzjcs);
                    k5.add(bjs);
                    break;
                case "49":
                    kssj.add("双随机科");
                    kssj.add(zcs);
                    kssj.add(zss);
                    kssj.add(zzxs);
                    kssj.add(zzjcs);
                    kssj.add(bjs);
                    break;
            }
            //
        }
        if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcj(稽查局)、all(沈阳市局)
            qj.add("全局");
        } else if ("all".equals(dataScope)) {
            qj.add("全市");
        }
        qj.add(zcsTotal);
        qj.add(zssTotal);
        qj.add(zzxsTotal);
        qj.add(zzjcsTotal);
        qj.add(bjsTotal);
        resMap.put("qj", qj);
        resMap.put("k1", k1);
        resMap.put("k2", k2);
        resMap.put("k3", k3);
        resMap.put("k4", k4);
        resMap.put("k5", k5);
        resMap.put("kssj", kssj);
        resMap.put("dataScope", dataScope);
        return resMap;
    }

    @Override
    public Map<String, List> indexJiAn() {
        Map<String, List> resMap = new HashMap<>();
        List<Object> zc = new ArrayList<>();
        List<Object> zs = new ArrayList<>();
        List<Object> zzx = new ArrayList<>();
        List<Object> bj = new ArrayList<>();
        List<Object> ja = new ArrayList<>();
        List<Map<String, Object>> jaMapData = statisticsMapper.indexJiAn();
        for (Map objMap : jaMapData) {
            zc.add(Integer.valueOf(String.valueOf(objMap.get("ZCS"))));
            zs.add(Integer.valueOf(String.valueOf(objMap.get("ZSS"))));
            zzx.add(Integer.valueOf(String.valueOf(objMap.get("ZZXS"))));
            bj.add(Integer.valueOf(String.valueOf(objMap.get("BJS"))));
            ja.add(Integer.valueOf(String.valueOf(objMap.get("JAS"))));
        }
        resMap.put("zc", zc);
        resMap.put("zs", zs);
        resMap.put("zzx", zzx);
        resMap.put("bj", bj);
        resMap.put("ja", ja);
        return resMap;
    }

    @Override
    public Map<String, List> indexNknsh() {
        Map<String, List> resMap = new HashMap<>();
        List<Object> tx = new ArrayList<>();
        List<Object> db = new ArrayList<>();
        List<Map<String, Object>> jaMapData = statisticsMapper.indexNknsh();
        for (Map objMap : jaMapData) {
            tx.add(Integer.valueOf(String.valueOf(objMap.get("TXS"))));
            db.add(Integer.valueOf(String.valueOf(objMap.get("DBS"))));
        }
        resMap.put("tx", tx);
        resMap.put("db", db);
        return resMap;
    }

    private void paramHandler(JcjfReq req) {
        String yearTmp = req.getStatisticsYear();
        String finalYear = yearTmp + "-01-01";
        req.setStatisticsYear(finalYear);
        String monthTmp = req.getStatisticsMonth();
        if (!"0".equals(monthTmp)) {
            monthTmp = yearTmp + monthTmp;
            req.setStatisticsMonth(monthTmp);
        }

        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String swjgDmTmp = currentSwjgDm.substring(0, 9);
        req.setAjszjgDm(swjgDmTmp + "00");
        req.setJcbmDm1(swjgDmTmp + "41");
        req.setJcbmDm2(swjgDmTmp + "42");
        req.setJcbmDm3(swjgDmTmp + "43");
        req.setJcbmDm4(swjgDmTmp + "44");
        req.setJcbmDm5(swjgDmTmp + "45");
    }


    @Override
    @DS("oracle")
    public Page anjianxiazhuan(AjxzReq req) {
        Page page = new Page(req.getPage(), req.getLimit());
        LambdaQueryWrapper<AjcxRecord> queryWrapper = Wrappers.lambdaQuery();
        //queryWrapper.apply("to_char(larq,'yyyy')={0}", String.valueOf(DateUtils.getNowYear()));
        queryWrapper.like(AjcxRecord::getJcry, req.getSwryDm());
        queryWrapper.eq(AjcxRecord::getJcbmDm, req.getSwjgDm());
        String ajztDm = req.getAjztDm();
        if ("901".equals(ajztDm)) {
            queryWrapper.eq(AjcxRecord::getAjjcztDm, ajztDm);
        } else if ("5".equals(ajztDm)) {
            queryWrapper.likeRight(AjcxRecord::getAjjcztDm, ajztDm);
            queryWrapper.apply("to_char(jarq,'yyyy')={0}", String.valueOf(DateUtils.getNowYear()));
        } else {
            queryWrapper.likeRight(AjcxRecord::getAjjcztDm, ajztDm);
        }
        Page resPage = ajcxRecordService.page(page, queryWrapper);
        return resPage;
    }


    @Override
    @DS("oracle")
    public Map<String, Object> gzzxFirstLevel(String swjgDm) {
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String currentRoleIds = httpSessionService.getCurrentRolesId();
        String dataScope = TsBqUtils.getDataScopeByRolesId(currentRoleIds);
        /**
         * jcj=当前登录人所在稽查局各个科室数据
         * all=各个稽查局的数据
         */
        /**
         *  手工维护表：
         * 1.稽查总分=稽查贡献积分+执法效能积分+成果运用积分+其他项目积分
         * 2.科室平均积分=稽查总分 / 科室案件所有检查人员总数
         * 3.全局排名 按照稽查总分进行排名
         *
         * 1.稽查贡献积分=查补积分+入库积分 +自查入库积分（暂时没有）
         * 2.执法效能积分=查处时限积分(JC_SY_GZZX_DF)+案件定性积分(jc_sy_ajdx_df)
         * 3.成果运用积分手工维护 jc_sy_ajdx_df
         * 4.其他项目积分=调查核实积分（jc_sy_dcxc_mx）+督办案件积分（jc_sy_dbaj_df）+其他积分（手工维护）jc_sy_ajdx_df
         * 5.科室负责人积分（手工维护） jc_sy_ajdx_df
         */
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        List<Map<String, Object>> resDatas = new ArrayList<>();
        if (TsBqUtils.isNotNull(swjgDm)) {
            tableDatas = statisticsMapper.gzzxFirstLevel(swjgDm.substring(0, 9));
        } else {
            if ("jcj".equals(dataScope)) {  //dataScope=数据权限：jcj(稽查一局)、all(沈阳市局)、jck(检查科)
                tableDatas = statisticsMapper.gzzxFirstLevel(currentSwjgDm.substring(0, 9));
            } else if ("all".equals(dataScope)) {
                tableDatas = statisticsMapper.gzzxFirstLevelSysj();
            } else if ("jck".equals(dataScope)) {
                tableDatas = statisticsMapper.gzzxFirstLevelKs(currentSwjgDm);
            }
        }
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            double jcgxjf = Double.valueOf(String.valueOf(currentMap.get("jcgxjf")));//稽查贡献积分
            int zfxnjf = Integer.valueOf(String.valueOf(currentMap.get("zfxnjf")));//执法效能积分
            int qtxmjf = Integer.valueOf(String.valueOf(currentMap.get("qtxmjf")));//其他项目积分
            int cgyyjf = Integer.valueOf(String.valueOf(currentMap.get("cgyyjf")));//成果运用积分
            int jcryzs = Integer.valueOf(String.valueOf(currentMap.get("jcryzs")));//稽查人员总数
            int ksfzrjf = Integer.valueOf(String.valueOf(currentMap.get("ksfzrjf")));//稽查人员总数
            //稽查总分=稽查贡献积分+执法效能积分+成果运用积分+其他项目积分
            double jczf = jcgxjf + zfxnjf + qtxmjf + cgyyjf;
            //科室平均积分=稽查总分 / 科室案件所有检查人员总数
            double kspjjf = 0.0;
            if (jcryzs != 0) {
                kspjjf = jczf / jcryzs;
            }
            //String format_kspjjf = String.format("%.2f", kspjjf);
            currentMap.put("jczf", Double.valueOf(String.format("%.2f", jczf)));
            currentMap.put("kspjjf", Double.valueOf(String.format("%.2f", kspjjf)));
            currentMap.put("ksfzrjf", Double.valueOf(String.format("%.2f", kspjjf + ksfzrjf)));
            currentMap.put("zfxnjf", zfxnjf);
            resDatas.add(currentMap);
        }
        resMap.put("tableDatas", this.cunstomSort(resDatas));
        return resMap;
    }

    private List<Map<String, Object>> cunstomSort(List<Map<String, Object>> datas) {
        String fieldName = "jczf";
        Collections.sort(datas, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> map1, Map<String, Object> map2) {
                double value1 = (double) map1.get(fieldName);
                double value2 = (double) map2.get(fieldName);
                return Double.compare(value2, value1);
            }
        });
        int rank = 1;
        for (Map<String, Object> data : datas) {
            data.put("qjpm", rank);
            rank++;
        }

        return datas;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> gzzxSecondLevel(SelectchiefReqVo req) {
        String swjgDm = req.getSwjgDm();
        //type用来判断是哪个的下钻 JCGXJF  ZFXNJF  CGYYJF  QTXMJF  KSFZRJF
        String type = req.getType();
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        //List<Map<String,Object>>  resDatas = new ArrayList<>();
        switch (type) {
            case "JCGXJF":
                tableDatas = statisticsMapper.gzzxSecondLevelJcgxjf(swjgDm);
                break;
            case "ZFXNJF":
                tableDatas = statisticsMapper.gzzxSecondLevelZfxnjf(swjgDm);
                break;
            case "CGYYJF":
                tableDatas = statisticsMapper.gzzxSecondLevelCgyyjf(swjgDm);
                break;
            case "QTXMJF":
                tableDatas = statisticsMapper.gzzxSecondLevelQtxmjf(swjgDm);
                break;
            case "KSFZRJF":
                tableDatas = statisticsMapper.gzzxSecondLevelKsfzrjf(swjgDm);
                Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
                while (iterator.hasNext()) {
                    Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
                    currentMap.put("kspjjf", req.getKspjjf());
                }
                break;
        }
        resMap.put("tableDatas", tableDatas);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> gzzxThirdLevel(SelectchiefReqVo req) {
        String swjgDm = req.getSwjgDm();
        //type用来判断是哪个的下钻 JCCBJF  JCRKJF  AJCCSXJF  AJDXJF  DCHSAJJF  DBAJJF
        String type = req.getType();
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> tableDatas = null;
        long total = 0;
        switch (type) {
            case "JCCBJF":
                tableDatas = statisticsMapper.gzzxThirdLevelJccbjfMx(req);
                total = statisticsMapper.gzzxThirdLevelJccbjfMxTotal(swjgDm);
                break;
            case "JCRKJF":
                tableDatas = statisticsMapper.gzzxThirdLevelJcrkjfMx(req);
                total = statisticsMapper.gzzxThirdLevelJcrkjfMxTotal(swjgDm);
                break;
            case "AJCCSXJF":
                tableDatas = statisticsMapper.gzzxThirdLevelAjccsxjfMx(req);
                total = statisticsMapper.gzzxThirdLevelAjccsxjfMxTotal(swjgDm);
                break;
            case "AJDXJF":
                tableDatas = statisticsMapper.gzzxThirdLevelAjdxjfMx(req);
                total = statisticsMapper.gzzxThirdLevelAjdxjfMxTotal(swjgDm);
                break;
            case "DCHSAJJF":
                tableDatas = statisticsMapper.gzzxThirdLevelDchsajjfMx(req);
                total = statisticsMapper.gzzxThirdLevelDchsajjfMxTotal(swjgDm);
                break;
            case "DBAJJF":
                tableDatas = statisticsMapper.gzzxThirdLevelDbajjfMx(req);
                total = statisticsMapper.gzzxThirdLevelDbajjfMxTotal(swjgDm);
                break;
        }
        resMap.put("tableDatas", tableDatas);
        resMap.put("tableDatasTotal", total);
        return resMap;
    }


    @Override
    public Map<String, Object> jajzayjzb() {
        Map<String, Object> resMap = new HashMap<>();
        List<Map<String, Object>> resDatas = new ArrayList<>();
        List<Map<String, Object>> tableDatas = statisticsMapper.jajzayjzb();
        Iterator<Map<String, Object>> iterator = tableDatas.iterator(); // 获取迭代器
        while (iterator.hasNext()) {
            Map<String, Object> currentMap = iterator.next(); // 获取当前Map对象
            int jcs = Integer.valueOf(String.valueOf(currentMap.get("JCS")));
            int sls = Integer.valueOf(String.valueOf(currentMap.get("SLS")));
            int zxs = Integer.valueOf(String.valueOf(currentMap.get("ZXS")));
            int cxs = Integer.valueOf(String.valueOf(currentMap.get("CXS")));
            int bjs = Integer.valueOf(String.valueOf(currentMap.get("BJS")));
            int zjs = Integer.valueOf(String.valueOf(currentMap.get("ZJS")));
            int dividend = zjs + bjs;
            int divisor = jcs + sls + zxs + cxs + bjs + zjs;
            String percentage = "";
            DecimalFormat df = new DecimalFormat("0.00"); // 设置格式化输出
            if (divisor == 0) {
                percentage = df.format(0.00) + "%"; // 格式化为百分比字符串
            } else {
                double result = (double) dividend / divisor * 100; // 计算百分率
                percentage = df.format(result) + "%"; // 格式化为百分比字符串
            }
            currentMap.put("QLV", percentage);
            resDatas.add(currentMap);
        }
        resMap.put("tableDatas", resDatas);
        return resMap;
    }


    @Override
    @DS("oracle")
    public List<JbxEntity> queryJbx() {
        List<JbxEntity> resList = new ArrayList<>();
        //全市
        JbxEntity qsjbxEntity = new JbxEntity();
        qsjbxEntity.setDw("全市");
        resList.add(qsjbxEntity);
        //稽查局
        JbxEntity jcjbxEntity = new JbxEntity();
        jcjbxEntity.setDw("市稽查局");
        resList.add(jcjbxEntity);
        //一局
        JbxEntity yjjbxEntity = new JbxEntity();
        yjjbxEntity.setDw("第一稽查局");
        resList.add(yjjbxEntity);
        //二局
        JbxEntity ejjbxEntity = new JbxEntity();
        ejjbxEntity.setDw("第二稽查局");
        resList.add(ejjbxEntity);
        //三局
        JbxEntity sjjbxEntity = new JbxEntity();
        sjjbxEntity.setDw("第三稽查局");
        resList.add(sjjbxEntity);
        return resList;
    }
}
